package com.meitutest.autoscript.T9;

import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiWatcher;

import com.meitutest.autoscript.utils.TestReport;

import java.util.regex.Pattern;

/**
 * Created by CrystalChen on 2017/12/18.
 */

public class T9Watcher implements UiWatcher {
    UiDevice mDevice;

    public T9Watcher(UiDevice mDevice) {
        this.mDevice = mDevice;
    }

    @Override
    public boolean checkForCondition() {
        if (mDevice.hasObject(By.text(Pattern.compile("同意|OK|确定|Agree|允许|Allow|知道了")))) {
            mDevice.findObject(By.text(Pattern.compile("同意|OK|确定|Agree|允许|Allow|知道了"))).click();
            TestReport.i("MyWatcher_checkForCondition: 发现 同意|OK|确定|Agree 弹窗");
            return true;
        } else if (mDevice.hasObject(By.res("com.android.settings:id/text2_ofnote"))){
            mDevice.pressBack();
            TestReport.i("T9Watcher_checkForCondition: 发现登录美图帐号弹窗");
        }
        return false;
    }
}
